﻿using System;
using System.Collections.Generic;

using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;

public partial class per_documentary_me : MpageBase
{
    protected int m = ReadRequest.RequestInt("m");
    protected List<Model.LotteryChippedUser> gendanuser = null;
    protected List<Model.LotteryChipped> lottery = null;
    protected int gdCount = 0;
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            getLotteruIdList();
        }
    }
    public string select(object userid)
    {
        Model.CMember cm = null;
        cm = BLL.CMember.GetModel(long.Parse(userid.ToString()));
        return cm != null ? cm.nickname : "暂无姓名";
    }
    public Model.LotteryChippedUser getInfo(int userid, int lotteryid)
    {
        string sql = "select top 1 * from LotteryChippedUser where UserID=" + userid + " and LotteryChippedid=" + lotteryid + " order by Id desc";

        return BLL.LotteryChippedUser.NewsTopOne(sql);
    }
    protected void getLotteruIdList()
    {
        PagedDataSource pds = new PagedDataSource();
        string sql = "";
        int type = int.Parse(this.typeslddl.SelectedValue);

        if (type > 0)
        {
            sql = " UserID=" + loginUserInfo.Id + " and LotteryType=" + type;
        }
        else
        {

            sql = " UserID=" + loginUserInfo.Id;
        }

        int times = int.Parse(this.timesl.SelectedValue.ToString());
        if (times == 0)
        {
            sql += " and datediff(day,[AddTime],getdate())=0 ";
        }
        else if (times == 1)
        {
            sql += " and datediff(week,[AddTime],getdate())=0 ";
        }
        else if (times == 2)
        {
            sql += " and datediff(month,[AddTime],getdate())=0";
        }
        else if (times == 3)
        {
            sql += " and datediff(month,[AddTime],getdate())<=3 ";
        }
        else if (times == 4)
        {
            sql += " and datediff(month,[AddTime],getdate())<=6 ";
        }

        //跟单人员 
        gendanuser = BLL.LotteryChippedUser.GetPageListBysql(0, int.MaxValue, sql, out gdCount);
        string idlist = "";
        if (gendanuser != null)
        {
            foreach (Model.LotteryChippedUser d in gendanuser)
            {
                idlist += d.LotteryChippedId + ",";
            }
        }
        idlist = idlist.TrimEnd(',');
        int count = 0;
        if (idlist != "")
        {
            lottery = BLL.LotteryChipped.GetPageListBysql(0, int.MaxValue, "id in (" + idlist + ")", out count);
        }

        if (lottery != null && lottery.Count > 0)
        {
            AspNetPager1.Visible = true;
            AspNetPager1.RecordCount = count;
            pds.AllowPaging = true;
            pds.PageSize = AspNetPager1.PageSize;
            pds.CurrentPageIndex = AspNetPager1.CurrentPageIndex - 1;

        }
        else
        {
            AspNetPager1.Visible = false;
        }
    }
    protected void AspNetPager1_PageChanged(object sender, EventArgs e)
    {
        getLotteruIdList();
    }
    protected void typeslddl_SelectedIndexChanged(object sender, EventArgs e)
    {
        getLotteruIdList();
    }
    protected void timesl_SelectedIndexChanged(object sender, EventArgs e)
    {
        getLotteruIdList();
    }
}